<?php

/**
 * @author Roshan
 * 
 * 
 */
class plugins {

    private static $hooks;
    private $plugins = array();

    function __construct() {
        $this->getActivePlugins();
    }

    public static function addHook($hook, $func, $pri = 5) {
        
    }

    function run() {
        if (is_array($this->plugins)) {
            foreach ($this->plugins as $key => $value) {
                include PLUGIN_PATH . $value['path'];
            }
        }
    }

    function getActivePlugins() {
        $this->plugins = unserialize(preference::newInstance()->getPreference('active_plugins'));
    }

    function activate($plugin) {
        if (!is_array($plugin)) {
            return false;
        }

        if (!array_key_exists($plugin['name'], $this->plugins)) {
            $this->plugins[$plugin['name']] = $plugin;
        }

        preference::newInstance()->setPreference('active_plugins', "'" . serialize($this->plugins) . "'");
        $this->getActivePlugins();
    }

    function deactivate($name) {
        if (array_key_exists($name, $this->plugins)) {
            unset($this->plugins[$name]);
        }
        preference::newInstance()->setPreference('active_plugins', "'" . serialize($this->plugins) . "'");
        $this->getActivePlugins();
    }

    public static function removeHook($hook, $func) {
        
    }

    public static function runHook($hook) {
        
    }

}

?>